<template>
  <div class="financial-balance">
    <vertical-table :page="pageIndex + '/' + pageCount" :label-width="215" class="table" :labels="labels" :coldata="colData" @lastpage="handleLastPage" @nextpage="handleNextPage" @edit="handleEdit"></vertical-table>
  </div>
</template>

<script>
import { requestAjax } from '../../common.js'
import CONSTANT from '../../constant/constant.js'

export default {
  data() {
    return {
      labels: [
        {
          label: 'rptMaster',
          name: '报表主体'
        },
        {
          label: 'isCheck',
          name: '报表是否审计'
        },
        {
          label: 'creatorName',
          name: '报表录入人'
        },
        {
          label: 'currencyDesc',
          name: '报表币种'
        },
        {
          label: 'attachment',
          name: '报表附件'
        },
        {
          label: '',
          name: false,
          dark: true
        },
        {
          label: 'cashRecpSgAndRs',
          name: '销售商品、提供劳务收到的现金'
        },
        {
          label: 'recpTaxRends',
          name: '收到的税费返还'
        },
        {
          label: 'otherCashRecpRalOperAct',
          name: '收到其他与经营活动有关的现金'
        },
        {
          label: 'runInflowsCash',
          name: '经营活动现金流入小计',
          dark: true
        },
        {
          label: 'runNetFlows',
          name: '经营活动产生的现金流量净额',
          dark: true
        },
        {
          label: 'cashRecpDispWithdrwlInvest',
          name: '收回投资收到的现金'
        },
        {
          label: 'cashRecpReturnInvest',
          name: '取得投资收益收到的现金'
        },
        {
          label: 'netCashRecpDispFiolta',
          name: '处置固定资产、无形资产和其他长期资产收回的现金净额'
        },
        {
          label: 'netCashRecpDispSobu',
          name: '处置子公司及其他营业单位收到的现金净额'
        },
        {
          label: 'otherCashRecpRalInvAct',
          name: '收到其他与投资活动有关的现金'
        },
        {
          label: 'investInflowsCash',
          name: '投资活动现金流入小计',
          dark: true
        },
        {
          label: 'cashPayAcqConstFiolta',
          name: '构建固定资产、无形资产和其他长期资产支付的现金'
        },
        {
          label: 'cashPaidInvest',
          name: '投资支付的现金'
        },
        {
          label: 'netCashPayAquisSobu',
          name: '取得子公司及其他营业单位支付的现金净额'
        },
        {
          label: 'otherCashPayRalInvAct',
          name: '支付其他与投资活动有关的现金'
        },
        {
          label: 'investOutflowsCash',
          name: '投资活动现金流出小计',
          dark: true
        },
        {
          label: 'investNetFlows',
          name: '投资活动产生的现金流量净额',
          dark: true
        },
        {
          label: 'cashRecpCapContrib',
          name: '吸收投资收到的现金'
        },
        {
          label: 'cashRecpBorrow',
          name: '取得借款收到的现金'
        },
        {
          label: 'procIssueBonds',
          name: '发行债券收到的现金'
        },
        {
          label: 'otherCashRecpRalFncAct',
          name: '收到其他与筹资活动有关的现金'
        },
        {
          label: 'financingInflowsCash',
          name: '筹资活动现金流入小计',
          dark: true
        },
        {
          label: 'financingNetFlows',
          name: '筹资活动产生的现金流量净额',
          dark: true
        },
        {
          label: 'feeFxFluCash',
          name: '汇率变动对现金及现金等价物的影响'
        },
        {
          label: 'netIncrCashCashEquDm',
          name: '现金及现金等价物净增长额',
          dark: true
        },
        {
          label: 'cashCashEquBegPeriod',
          name: '加：期初现金及现金等价物余额'
        },
        {
          label: '',
          name: '期末现金及现金等价物余额'
        }
      ],
      colData: [ {}, {}, {} ],
      pageCount: 1,
      pageIndex: 1
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData(index = 1) {
      const url = CONSTANT.URL.COMPANY.FINANCIALCASHFLOW
      const params = {
        pageIndex: index,
        pageSize: 3,
        userId: this.$router.currentRoute.query.id,
        associationId:this.$router.currentRoute.query.userId || 0
      }
      requestAjax(url, '{}', params, res => {
        this.pageCount = res.data.pageCount
        this.pageIndex = index
        if (!res.data.bussData) return
        this.colData = res.data.bussData.map(i => {
          let totalNum = {
            cashRecpSgAndRs:i.cashRecpSgAndRs,
            recpTaxRends:i.recpTaxRends,
            otherCashRecpRalOperAct:i.otherCashRecpRalOperAct
          }
          let runInflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i]) && totalNum[i]) {
              runInflowsCash += Number(totalNum[i])
            }
          }

          totalNum = {
            casPayGoodsPurchServRec:i.casPayGoodsPurchServRec,
            cashPayBehEmpl:i.cashPayBehEmpl,
            payAllTypTax:i.payAllTypTax,
            otherCashPayRalOperAct:i.otherCashPayRalOperAct
          }
          let runOutflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i]) && totalNum[i]) {
              runOutflowsCash += Number(totalNum[i])
            }
          }

          totalNum = {
            cashRecpDispWithdrwlInvest:i.cashRecpDispWithdrwlInvest,
            cashRecpReturnInvest:i.cashRecpReturnInvest,
            netCashRecpDispFiolta:i.netCashRecpDispFiolta,
            netCashRecpDispSobu:i.netCashRecpDispSobu,
            otherCashRecpRalInvAct:i.otherCashRecpRalInvAct
          }
          let investInflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i]) && totalNum[i]) {
              investInflowsCash += Number(totalNum[i])
            }
          }

          totalNum = {
            cashPayAcqConstFiolta:i.cashPayAcqConstFiolta,
            cashPaidInvest:i.cashPaidInvest,
            netCashPayAquisSobu:i.netCashPayAquisSobu,
            otherCashPayRalInvAct:i.otherCashPayRalInvAct
          }
          let investOutflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i]) && totalNum[i]) {
                    investOutflowsCash += Number(totalNum[i])
            }
          }
          totalNum = {
            cashRecpCapContrib:i.cashRecpCapContrib,
            cashRecpBorrow:i.cashRecpBorrow,
            procIssueBonds:i.procIssueBonds,
            otherCashRecpRalFncAct:i.otherCashRecpRalFncAct
          }
          let financingInflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i])&&totalNum[i]) {
              financingInflowsCash += Number(totalNum[i])
            }
          }
          totalNum = {
            cashPrepayAmtBorr:i.cashPrepayAmtBorr,
            cashPayDistDpcpIntExp:i.cashPayDistDpcpIntExp,
            otherCashPayRalFncAct:i.otherCashPayRalFncAct
          }
          let financingOutflowsCash = 0
          for (let i in totalNum) {
            if (!isNaN(totalNum[i]) && totalNum[i]) {
              financingOutflowsCash += Number(totalNum[i])
            }
          }
          return {
            header: {
              text: i.rptDate,
              opText: '编辑',
              opEvent: 'edit'
            },
            data: {
              ...i,
              attachment: i.attachmentId ? {
                text: i.attachmentFile.fileName,
                color: '#0087DC',
                download: i.attachmentFile.fileUrl
              } : {
                text: '上传补充详细附件',
                color: '#ED7018',
                event: 'edit'
              },
              isCheck: i.isCheck == 'y' ? '是' : '否',
              runInflowsCash,
              runNetFlows: runInflowsCash - runOutflowsCash,
              investInflowsCash,
              investOutflowsCash,
              investNetFlows: investInflowsCash - investOutflowsCash,
              financingInflowsCash,
              financingNetFlows: financingInflowsCash - financingOutflowsCash,
              netIncrCashCashEquDm: runInflowsCash - runOutflowsCash + investInflowsCash - investOutflowsCash + financingInflowsCash - financingOutflowsCash,
              cashCashEquEndPeriod: runInflowsCash - runOutflowsCash + investInflowsCash - investOutflowsCash + financingInflowsCash - financingOutflowsCash + i.cashCashEquBegPeriod
            }
          }
        })
        while(this.colData.length < 3) {
          this.colData.push([{header: {}, data: {}}])
        }
      })
    },
    handleLastPage() {
      if (this.pageIndex <= 1) {
        this.$message.warning('已经是第一页了')
      } else {
        this.loadData(this.pageIndex - 1)
      }
    },
    handleNextPage() {
      if (this.pageIndex >= this.pageCount) {
        this.$message.warning('已经是最后一页了')
      } else {
        this.loadData(this.pageIndex + 1)
      }
    },
    handleEdit(item) {
      this.$router.push({
        path: '/partner/financialInfo_v2/financeOperatingEdit', 
        query: {
          id: item.data.id,
          userId: item.data.userId,
          name: this.$route.query.name
        }
      })
    }
  },
  components: {
    "vertical-table": () => import("../common/vertical-table.vue")
  }
}
</script>

<style scoped>
.table {
  margin-right: 40px;
}
</style>
